using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace ScreenSizeCalc
{
    public partial class TVSize : Form
    {
        //Import del comando per mostrare/nascondere la tastiera
        [DllImport("coredll.dll")]
        private static extern bool SipShowIM(int dwFlag);

        //Definizione delle due diagonali
        double diag169 = Math.Sqrt(Math.Pow(9, 2) + Math.Pow(16, 2));
        double diag43 = 5;

        public TVSize()
        {
            InitializeComponent();
        }
        
        private void button1_Click(object sender, EventArgs e)
        {
            if (diagonale.Text != "")
            {
                SipShowIM(0);
                double diago = System.Convert.ToDouble(diagonale.Text) * 2.54;
                double alt, largh;
                if (formato1.SelectedIndex == 0)
                {
                    alt = (diago * 3) / diag43;
                    largh = (diago * 4) / diag43;
                    altezza.Text = (Math.Round(alt)).ToString();
                    larghezza.Text = (Math.Round(largh)).ToString();
                    dist1_min.Text = (Math.Round(((diago * 3) / 100), 2)).ToString();
                    dist1_max.Text = (Math.Round(((diago * 6) / 100), 2)).ToString();
                }
                else if (formato1.SelectedIndex == 1)
                {
                    alt = (diago * 9) / diag169;
                    largh = (diago * 16) / diag169;
                    altezza.Text = (Math.Round(alt)).ToString();
                    larghezza.Text = (Math.Round(largh)).ToString();
                    dist1_min.Text = (Math.Round(((diago * 1.5) / 100), 2)).ToString();
                    dist1_max.Text = (Math.Round(((diago * 3) / 100), 2)).ToString();
                }
            }
        }

        private void formato1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (formato1.SelectedIndex == 0)
            {
                panel169.Visible = false;
                panel43.Visible = true;
            }
            else if (formato1.SelectedIndex == 1)
            {
                panel43.Visible = false;
                panel169.Visible = true;
            }
        }

        private void formato2_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (formato2.SelectedIndex == 0)
            {
                panel1692.Visible = false;
                panel432.Visible = true;
            }
            else if (formato2.SelectedIndex == 1)
            {
                panel432.Visible = false;
                panel1692.Visible = true;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (base_input.Text != "")
            {
                SipShowIM(0);
                double diago;
                double largh = System.Convert.ToDouble(base_input.Text);
                if (formato1.SelectedIndex == 0)
                {
                    diago = largh * diag43 / 4;
                    diagonale_output.Text = (Math.Round(diago / 2.54)).ToString();
                    dist2_min.Text = (Math.Round(((diago * 3) / 100), 2)).ToString();
                    dist2_max.Text = (Math.Round(((diago * 6) / 100), 2)).ToString();
                }
                else if (formato1.SelectedIndex == 1)
                {
                    diago = largh * diag169 / 16;
                    diagonale_output.Text = (Math.Round(diago / 2.54)).ToString();
                    dist2_min.Text = (Math.Round(((diago * 1.5) / 100), 2)).ToString();
                    dist2_max.Text = (Math.Round(((diago * 3) / 100), 2)).ToString();
                }
            }
        }

        private void menuItem1_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void diagonale_GotFocus(object sender, EventArgs e)
        {
            SipShowIM(1);
        }

        private void base_input_GotFocus(object sender, EventArgs e)
        {
            SipShowIM(1);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (dist3.Text != "")
            {
                SipShowIM(0);
                double diago;
                double dist = System.Convert.ToDouble(dist3.Text);
                if (formato3.SelectedIndex == 0)
                {
                    diago = dist / 4.5;
                    diagonale_output3.Text = (Math.Round(diago / 2.54)).ToString();
                }
                else if (formato3.SelectedIndex == 1)
                {
                    diago = dist / 2.25;
                    diagonale_output3.Text = (Math.Round(diago / 2.54)).ToString();
                }
            }
        }

        private void dist3_GotFocus(object sender, EventArgs e)
        {
            SipShowIM(1);
        }

        private void formato3_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (formato3.SelectedIndex == 0)
            {
                panel1693.Visible = false;
                panel433.Visible = true;
            }
            else if (formato3.SelectedIndex == 1)
            {
                panel433.Visible = false;
                panel1693.Visible = true;
            }
        }

              
    }
}